package com.platform.common.result;

import lombok.*;
import org.apache.commons.lang3.StringUtils;

/**
 * @author GH
 * @description 自定义异常类
 **/
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ApiException extends RuntimeException {
    public int code;
    public String message = "";
    public boolean isPrint = false;

    public ApiException(ApiExceptionEnum e) {
        this.code = e.code;
        this.message = e.message;
        this.isPrint = e.isPrint;
    }

    public ApiException(ApiExceptionEnum e, String additionalMessage) {
        this.code = e.code;
        if (StringUtils.isNotBlank(additionalMessage)){
            this.message = additionalMessage;
        }else {
            this.message = e.message;
        }
        this.isPrint = e.isPrint;
    }

    public ApiException message(String message){
        this.setMessage(message);
        return this;
    }

    public ApiException code(Integer code){
        this.setCode(code);
        return this;
    }
}
